# -*- coding: utf-8 -*-
"""
Created on Tue May 14 11:31:28 2019

@author: Soly 

基于对率回归进行划分选择的决策树

"""
import TrainTree as tt
from DrawTree import draw
import numpy as np
#==================================================
#                表4.3 西瓜数据集3.0
#==================================================
FeatureName=['色泽','根蒂','敲声','纹理','脐部','触感','密度','含糖率']
LabelName={1:'好瓜',0:'坏瓜'}
X=[['青绿','蜷缩','浊响','清晰','凹陷','硬滑',0.697,0.460],
   ['乌黑','蜷缩','沉闷','清晰','凹陷','硬滑',0.774,0.376],
   ['乌黑','蜷缩','浊响','清晰','凹陷','硬滑',0.634,0.264],
   ['青绿','蜷缩','沉闷','清晰','凹陷','硬滑',0.608,0.318],
   ['浅白','蜷缩','浊响','清晰','凹陷','硬滑',0.556,0.215],
   ['青绿','稍蜷','浊响','清晰','稍凹','软粘',0.403,0.237],
   ['乌黑','稍蜷','浊响','稍糊','稍凹','软粘',0.481,0.149],
   ['乌黑','稍蜷','浊响','清晰','稍凹','硬滑',0.437,0.211],
   ['乌黑','稍蜷','沉闷','稍糊','稍凹','硬滑',0.666,0.091],
   ['青绿','硬挺','清脆','清晰','平坦','软粘',0.243,0.267],
   ['浅白','硬挺','清脆','模糊','平坦','硬滑',0.245,0.057],
   ['浅白','蜷缩','浊响','模糊','平坦','软粘',0.343,0.099],
   ['青绿','稍蜷','浊响','稍糊','凹陷','硬滑',0.639,0.161],
   ['浅白','稍蜷','沉闷','稍糊','凹陷','硬滑',0.657,0.198],
   ['乌黑','稍蜷','浊响','清晰','稍凹','软粘',0.360,0.370],
   ['浅白','蜷缩','浊响','模糊','平坦','硬滑',0.593,0.042],
   ['青绿','蜷缩','沉闷','稍糊','稍凹','硬滑',0.719,0.103]]
Y=[1]*8+[0]*9
DataType=[[type(''), '青绿', '乌黑', '浅白'],    #三个取值无明显序关系 
          [type(''), '蜷缩', '稍蜷', '硬挺'],    #有序，根蒂蜷缩程度逐渐减弱
          [type(''), '沉闷', '浊响', '清脆'],    #有序，敲声清晰程度逐渐增大
          [type(''), '清晰', '稍糊', '模糊'],    #有序，纹理清晰程度逐渐减弱 
          [type(''), '凹陷', '稍凹', '平坦'],    #有序，脐部凹陷程度逐渐减弱
          [type(''), '硬滑', '软粘'],            #只有两个取值，可视为有序
          [type(0.0)], 
          [type(0.0)]]
order=[False,True,True,True,True,True,True,True]  #各个属性的取值是否含有序关系


#==================================================
#              基于对率回归进行划分选择
#==================================================

normal=[None,'min-max','z-score']       #归一化方式，可以是:None(不作归一化),'min-max','z-score'

# 分别遍历以上所设置的参数lamuda和normal
for nm in normal:
    tree=tt.CreatTree(X,Y,[],[],FeatureName,LabelName,DataType=DataType,rule='LogisticReg',normal=nm,order=order)
    draw(tree,('西瓜数据集3.0-属性划分(对率回归)\n归一化:%s' %nm))